package com.xin.usermanagebackend.exception;


import com.xin.usermanagebackend.common.BaseResponse;
import com.xin.usermanagebackend.constant.ResultCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {
    @ExceptionHandler(BusinessException.class)
    public BaseResponse<?> businessException(BusinessException businessException){
        log.error("businessException",businessException);
        return new BaseResponse<>(businessException.getCode(),null,businessException.getMessage());
    }
    @ExceptionHandler(RuntimeException.class)
    public BaseResponse<?> runtimeException(RuntimeException runtimeException){
        log.error("runtimeException",runtimeException);
        return new BaseResponse<>(ResultCode.SYSTEM_ERROR,null,runtimeException.getMessage());
    }
}
